﻿
/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_HealthMemberPrintForm
 * 类型：       控制层
 * 功能说明：   会员健康情况信息打印页面
 * 作者：       徐傲明
 * 创建日期：   2008/02/22
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Master.Bean;
using Shpm.App.Master.Dao;
using System.Globalization;
using Shpm.App.Commons.Utils;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Text.RegularExpressions;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Master;

public partial class App_Input_HealthMemberPrintForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //接受数据
        string memberNo = Convert.ToString(Request.QueryString["MEMBER_NO"]);

        //打印
        set1(memberNo);    
    }

    private void set1(string memberNo)
    {
        MemoryStream stream = new MemoryStream();


        Document document = new Document(PageSize.A4, 80, 50, 30, 65);



        PdfWriter pdfWriter = PdfWriter.GetInstance(document, stream);
        document.Open();


        FontFactory.RegisterDirectory("c:\\Windows\\Fonts");

        FontSelector selector = new FontSelector();

        Font font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 14, Font.BOLD, new Color(0, 0, 0));

        selector.AddFont(font);


        //显示标题
        Paragraph title = new Paragraph(selector.Process("会员健康信息单"));
        //Paragraph title1 = new Paragraph(selector.Process(memberNo));

        title.Alignment = Element.ALIGN_CENTER;

        document.Add(title);


        //检索数据
        HealthMemberHealthDao dao = new HealthMemberHealthDao();
        HealthMemberHealthBean bean = new HealthMemberHealthBean();
        HealthMemberHealthBean dataBean = new HealthMemberHealthBean();
        HealthMemberHealthBean timeBean = new HealthMemberHealthBean();
        if (!string.IsNullOrEmpty(memberNo))
        {
            bean.MemberNo = memberNo;
        }
        dataBean = dao.GetHealthMemberHealth(bean);
        timeBean = dao.GetTime(bean);
        IList list = dao.GetList(bean);
        IList ilist = dao.GetCureList(bean);
        int iAge = Convert.ToInt32(DateTime.Now.Year) - Convert.ToInt32(Convert.ToDateTime(dataBean.MemberBirthday).Year);
        string age=Convert.ToString(iAge+1);


        //显示打印数据
        PdfPTable table = new PdfPTable(10);
        PdfPCell cell = new PdfPCell(new Paragraph(" "));

        //显示会员基本资料
        cell.Border = 0;
        cell.Colspan = 10;
        table.AddCell(cell);


        cell.Colspan = 2;
        font.Size = 10;
        cell.HorizontalAlignment = Element.ALIGN_CENTER;
        cell.Phrase = selector.Process("姓名：" + dataBean.MemberName);
        cell.BorderWidthBottom = 0.5f;
        cell.BorderColorBottom = new Color(0, 0, 0);
        table.AddCell(cell);


        cell.Colspan = 2;
        font.Size = 10;
        cell.HorizontalAlignment = Element.ALIGN_CENTER;
        cell.Phrase = selector.Process("性别：" + dataBean.MemberSex);
        cell.BorderWidthBottom = 0.5f;
        cell.BorderColorBottom = new Color(0, 0, 0);
        table.AddCell(cell);

        cell.Colspan = 2;
        font.Size = 10;
        cell.HorizontalAlignment = Element.ALIGN_CENTER;
        cell.Phrase = selector.Process("年龄：" + age);
        cell.BorderWidthBottom = 0.5f;
        cell.BorderColorBottom = new Color(0, 0, 0);
        table.AddCell(cell);

        cell.Colspan = 4;
        font.Size = 10;
        cell.HorizontalAlignment = Element.ALIGN_CENTER;
        if (timeBean != null)
        {
            cell.Phrase = selector.Process("入住时间：" + DateUtils.convertToString((DateTime)timeBean.MemberTime));
        }

         //无入住时间时
        else
        {
            cell.Phrase = selector.Process("入住时间：--");
        }
        cell.BorderWidthBottom = 0.5f;
        cell.BorderColorBottom = new Color(0, 0, 0);
        table.AddCell(cell);

        cell.Border = 0;
        cell.Colspan = 10;
        cell.Phrase = selector.Process("");
        table.AddCell(cell);


        //显示会员病历
        font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 10, Font.BOLD, new Color(0, 0, 0));
        selector = new FontSelector();
        cell.HorizontalAlignment = Element.ALIGN_LEFT;
        selector.AddFont(font);
        cell.Border = 0;
        cell.Colspan = 5;
        cell.Phrase = selector.Process("现在病历");
        table.AddCell(cell);


        cell.Border = 0;
        cell.Colspan = 5;
        cell.Phrase = selector.Process("既往病历");
        table.AddCell(cell);

        font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 9, Font.UNDEFINED, new Color(0, 0, 0));
        selector = new FontSelector();
        selector.AddFont(font);

        cell.Border = 0;
        cell.Colspan = 5;

        if (dataBean.MemberDisease == null)//无记录时
        {
            cell.Phrase = selector.Process("无记录");
        }
        else
        {
            cell.Phrase = selector.Process(dataBean.MemberDisease);
        }
        table.AddCell(cell);
        

        cell.Border = 0;
        cell.Colspan = 5;

        if (dataBean.MemberDiseaseHis == null)//无记录时
        {
            cell.Phrase = selector.Process("无记录");
        }
        else
        {
            cell.Phrase = selector.Process(dataBean.MemberDiseaseHis);
        }
        table.AddCell(cell);



        font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 7, Font.UNDEFINED, new Color(0, 0, 0));
        selector = new FontSelector();
        selector.AddFont(font);
        cell.Colspan = 10;
        cell.BorderWidthTop = 0.5f;
        cell.BorderColorBottom = new Color(0, 0, 0);
        cell.HorizontalAlignment = Element.ALIGN_LEFT;
        cell.Phrase = selector.Process("会员健康信息");
        table.AddCell(cell);



        cell.Border = 0;
        cell.Colspan = 10;
        cell.Phrase = selector.Process("");
        table.AddCell(cell);

        cell.Border = 0;
        cell.Colspan = 10;
        cell.Phrase = selector.Process("");
        table.AddCell(cell);






        //显示会员用药信息
        font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 10, Font.BOLD, new Color(0, 0, 0));
        selector = new FontSelector();
        selector.AddFont(font);
        cell.HorizontalAlignment = Element.ALIGN_CENTER;
        cell.Phrase = selector.Process("药品名称");
        cell.Border = 0;
        cell.Colspan = 2;
        table.AddCell(cell);

        cell.Border = 0;
        cell.Colspan = 2;
        cell.Phrase = selector.Process("用药剂量");
        table.AddCell(cell);

        cell.Border = 0;
        cell.Colspan = 2;
        cell.Phrase = selector.Process("用药单位");
        table.AddCell(cell);

        cell.Border = 0;
        cell.Colspan = 2;
        cell.Phrase = selector.Process("用药途径");
        table.AddCell(cell);

        cell.Border = 0;
        cell.Colspan = 2;
        cell.Phrase = selector.Process("用药频次");
        table.AddCell(cell);


        //数据输出
        font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 9, Font.UNDEFINED, new Color(0, 0, 0));
        selector = new FontSelector();
        selector.AddFont(font);
        if (list.Count == 0)//无记录时
        {
            cell.Colspan = 2;
            cell.Phrase = selector.Process("无记录");
            table.AddCell(cell);

            cell.Colspan = 2;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.Phrase = selector.Process("无记录");
            table.AddCell(cell);

            cell.Colspan = 2;
            cell.Phrase = selector.Process("无记录");
            table.AddCell(cell);

            cell.Colspan = 2;
            cell.Phrase = selector.Process("无记录");
            table.AddCell(cell);

            cell.Colspan = 2;
            cell.Phrase = selector.Process("无记录");
            table.AddCell(cell);
        }
        else
        {
            for (int i = 0; i < list.Count; i++)
            {
                bean = (list[i] as HealthMemberHealthBean);
                //cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 2;
                cell.Phrase = selector.Process(bean.MedicineName);
                table.AddCell(cell);

                cell.Colspan = 2;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.Phrase = selector.Process(Convert.ToString(bean.MedicineQuantity));
                table.AddCell(cell);

                cell.Colspan = 2;
                cell.Phrase = selector.Process(bean.MedicineUnit);
                table.AddCell(cell);

                cell.Colspan = 2;
                if (bean.MedicineApproach == null)
                {
                    cell.Phrase = selector.Process("");
                }
                else
                {
                    cell.Phrase = selector.Process(bean.MedicineApproach);
                }
                table.AddCell(cell);

                cell.Colspan = 2;
                //cell.Phrase = selector.Process(bean.MedicineFrequency);
                if (bean.MedicineFrequency == null)
                {
                    cell.Phrase = selector.Process("");
                }
                else
                {
                    cell.Phrase = selector.Process(bean.MedicineFrequency);
                }
                table.AddCell(cell);

                //count = count + Convert.ToDouble(bean.DinnerAmount);

            }
        }


        font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 7, Font.UNDEFINED, new Color(0, 0, 0));
        selector = new FontSelector();
        selector.AddFont(font);
        cell.Colspan = 10;
        cell.BorderWidthTop = 0.5f;
        cell.BorderColorBottom = new Color(0, 0, 0);
        cell.HorizontalAlignment = Element.ALIGN_LEFT;
        cell.Phrase = selector.Process("会员用药信息");
        table.AddCell(cell);



        cell.Border = 0;
        cell.Colspan = 10;
        cell.Phrase = selector.Process("");
        table.AddCell(cell);

        cell.Border = 0;
        cell.Colspan = 10;
        cell.Phrase = selector.Process("");
        table.AddCell(cell);



        //显示巡诊时间
        font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 10, Font.BOLD, new Color(0, 0, 0));
        selector = new FontSelector();
        selector.AddFont(font);
        cell.Colspan = 2;
        cell.Phrase = selector.Process("巡诊时间");
        table.AddCell(cell);
        cell.Colspan = 8;
        cell.Phrase = selector.Process("巡诊记录");
        table.AddCell(cell);
        



        //数据输出
        font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 9, Font.UNDEFINED, new Color(0, 0, 0));
        selector = new FontSelector();
        selector.AddFont(font);

        if (ilist.Count == 0)//无记录时候
        {
            cell.Colspan = 2;
            cell.Phrase = selector.Process("无记录");
            table.AddCell(cell);

            //cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.Colspan = 8;
            cell.Phrase = selector.Process("无记录");
            table.AddCell(cell);
        }
        else
        {
            for (int i = 0; i < ilist.Count; i++)
            {
                bean = (ilist[i] as HealthMemberHealthBean);
                //cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 2;
                cell.Phrase = selector.Process(DateUtils.convertToString((DateTime)bean.FactDate));
                table.AddCell(cell);

                //cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.Colspan = 8;
                cell.Phrase = selector.Process(bean.Conclusion);
                table.AddCell(cell);



                //count = count + Convert.ToDouble(bean.DinnerAmount);

            }
        }



        font = FontFactory.GetFont("simsun", BaseFont.IDENTITY_H, 7, Font.UNDEFINED, new Color(0, 0, 0));
        selector = new FontSelector();
        selector.AddFont(font);
        cell.Colspan = 10;
        cell.BorderWidthTop = 0.5f;
        cell.BorderColorBottom = new Color(0, 0, 0);

        
        cell.HorizontalAlignment = Element.ALIGN_LEFT;
        cell.Phrase = selector.Process("会员巡诊信息");
        table.AddCell(cell);







        document.Add(table);
        document.Close();
        Response.AddHeader("Cache-Control", "cache");
        Response.AddHeader("Content-Type", "application/pdf");
        Response.AddHeader("Content-Length", stream.GetBuffer().Length.ToString());
        // Response.AddHeader("Content-Disposition", "attachment;filename=shpm.pdf");
        Response.BinaryWrite(stream.GetBuffer());

        Response.End();
    }
}
